package com.example.hello.client.NavTabs;

import com.example.hello.BootstrapNavTabs;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentContainerConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

import java.util.Iterator;

@Connect(BootstrapNavTabs.class)
public class BootstrapNavTabsConnector extends AbstractComponentContainerConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapNavTabs.class);
    }

    @Override
    public VBootstrapNavTabs getWidget() {
        return (VBootstrapNavTabs) super.getWidget();
    }

    @Override
    public BootstrapNavTabsState getState() {
        return (BootstrapNavTabsState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapNavTabsState state = getState();

        VBootstrapNavTabs navTabs = getWidget();

        Iterator<Connector> itr = state.getLinks().iterator();
        while (itr.hasNext()) {
            navTabs.add(((ComponentConnector) itr.next()).getWidget());
        }
    }

    @Override
    public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

    }

    @Override
    public void updateCaption(ComponentConnector connector) {

    }

}
